﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.Entity.Core.Objects;
using System.Data.Entity.Core.Objects.DataClasses;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SilkeyERP.UI.Entities.Shared
{
    public partial class SalesPriceListChooser : BaseChooser
    {
        public SalesPriceListChooser()
        {
            InitializeComponent();
        }

        public IQueryable<Model.SalesPriceList> Query { get; set; }

        protected override void OnLoad()
        {
            this.Text = Properties.Resources.SalesPriceListChooserTitleForm;
            base.OnLoad();

            IQueryable<Model.SalesPriceList> query = new BL.SalesPriceListController().GetAll().AsQueryable();
            if (Query != null)
                query = Query;

            bsBaseChooser.DataSource = query.ToList();

            productsBindingSource.DataSource = new BL.ProductsController().GetAll();
            taxBindingSource.DataSource = new BL.TaxController().GetAll();
        }

        private void gvBaseChooser_MasterRowEmpty(object sender, DevExpress.XtraGrid.Views.Grid.MasterRowEmptyEventArgs e)
        {
            e.IsEmpty = false;
        }

        private void gvBaseChooser_MasterRowGetChildList(object sender, DevExpress.XtraGrid.Views.Grid.MasterRowGetChildListEventArgs e)
        {
            Model.SalesPriceList c = (Model.SalesPriceList)gvBaseChooser.GetRow(e.RowHandle);           

            e.ChildList = c.SalesPriceListDetails.ToList();
        }

        private void gvBaseChooser_MasterRowGetLevelDefaultView(object sender, DevExpress.XtraGrid.Views.Grid.MasterRowGetLevelDefaultViewEventArgs e)
        {
            e.DefaultView = gvDetailBaseChooser;
        }

        private void gvBaseChooser_MasterRowGetRelationCount(object sender, DevExpress.XtraGrid.Views.Grid.MasterRowGetRelationCountEventArgs e)
        {
            e.RelationCount = 1;
        }

        private void gvBaseChooser_MasterRowGetRelationName(object sender, DevExpress.XtraGrid.Views.Grid.MasterRowGetRelationNameEventArgs e)
        {
            e.RelationName = "SalesPriceListDetails";
        }

        //private void gvBaseChooser_MasterRowEmpty(object sender, DevExpress.XtraGrid.Views.Grid.MasterRowEmptyEventArgs e)
        //{
        //    Model.SalesPriceList c = (Model.SalesPriceList)gvBaseChooser.GetRow(e.RowHandle);
        //    e.IsEmpty = c.SalesPriceListDetails.Count == 0;
        //}

        //private void gvBaseChooser_MasterRowGetRelationCount(object sender, DevExpress.XtraGrid.Views.Grid.MasterRowGetRelationCountEventArgs e)
        //{
        //    e.RelationCount = 1;
        //}

        //private void gvBaseChooser_MasterRowGetRelationName(object sender, DevExpress.XtraGrid.Views.Grid.MasterRowGetRelationNameEventArgs e)
        //{
        //    e.RelationName = "SalesPriceListDetails";
        //}

        //private void gvBaseChooser_MasterRowGetChildList(object sender, DevExpress.XtraGrid.Views.Grid.MasterRowGetChildListEventArgs e)
        //{
        //    Model.SalesPriceList c = (Model.SalesPriceList)gvBaseChooser.GetRow(e.RowHandle);
        //    e.ChildList =  new BindingSource(c.SalesPriceListDetails, "SalesPriceListDetails");
        //}

    }
}
